 
const app = getApp()

Page({
  data: {
    config: app.globalData.config,
    wxUser: null,
    userInfo: null,
    fileList:[]
  },
  onShow(){
    app.doLogin()
    let wxUser = app.globalData.wxUser
    this.setData({
      wxUser: wxUser
    })
    this.wxUserGet() 
  },
  onLoad(){
    
  },  
  //获取商城用户信息
  wxUserGet(){ 
    app.api.wxUserGet()
      .then(res => {
        this.setData({
          userInfo: res.data
        })
      })
  },
  inputNick(e){
    this.setData({
      'userInfo.nickName': e.detail
    })
  },
  onChange(e){
    this.setData({
      'userInfo.sex': e.detail
    })
  },
  handleSave(){
    app.api.editUser(this.data.userInfo)
    .then(res => {
      wx.showToast({
        title: '保存成功',
      })
      this.wxUserGet() 
      wx.switchTab({
        url: '/pages/user/user-center/index',
      })
    })
  },
  // 授权 手机
  getPhoneNumber(e){
    console.log(e)
    var params = {
      jsCode: e.detail.code
    }
    app.api.getWxPhone(params).then(res => {
      console.log(res,'res')
      this.setData({
        'userInfo.phone': res.msg
      })
    })
  }
})
